package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.aopLog.OperateLog;
import com.huilian.iotbox.admin.wap.dao.MemberDao;
import com.huilian.iotbox.admin.wap.service.FeedbackService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.FeedbackDto;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 龙 路 飞
 * @CreateDate: 2021-10-16 09:21
 * @Description:
 */
@RestController
@RequestMapping("/api/feedback")
public class FeedbackController extends UserInfoController {
    @Autowired
    private FeedbackService feedbackService;
    @Autowired
    private MemberDao memberDao;

    @PostMapping("/findList")
    public ServerResponse findList(@RequestBody FeedbackDto feedbackDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        feedbackDto.setUserInfo(userInfo);
        return ServerResponse.createBySuccess(feedbackService.findList(feedbackDto));
    }

    @GetMapping("/findByIdAndUserId")
    public ServerResponse findByIdAndUserId(Integer feedbackId, HttpServletRequest request) {
        FeedbackDto feedbackDto = new FeedbackDto();
        UserInfo userInfo = super.getLoginUserInfo(request);
        feedbackDto.setUserInfo(userInfo);
        feedbackDto.setId(feedbackId);
        return ServerResponse.createBySuccess(feedbackService.findByIdAndUserId(feedbackDto));
    }

    @PutMapping("/update")
    public ServerResponse update(@RequestBody FeedbackDto feedbackDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        feedbackDto.setUserId(userInfo.getId());
        return feedbackService.update(feedbackDto);
    }

}
